#include <iostream>
#include <fstream>

using namespace std;

int main()
 {
	fstream fin("1.jpg", ios::in | ios::binary);
	fstream fout("2.jpg", ios::out | ios::binary);
	fin.seekg(0, ios::end);
	cout << "Size: " << fin.tellg() << endl;
	fin.seekg(0);
	if(fin == NULL || fout == NULL) {
		cout <<"error";
		return 1;
	}

	// read from the first file then write to the second file
	int packetSize = 95;
	char packet[packetSize];
	memset(packet,'0',0);
	int i;
	int charsRead = 0;
	int charsWritten = 0;
	while(fin.good()) {
		for(i = 0;i<packetSize && !fin.eof();i++){
			packet[i] = fin.get();
			charsRead++;
		}
		for(int j = 0; j < i; j++){
			if(fout.good())
				fout.put(packet[j]);
				charsWritten++;
		}
		memset(packet,'0',0);
	}
	cout << "Read: " << charsRead << " | Written: " << charsWritten << endl;

	fin.close();
	fout.close(); 

	return 0;
 }
